import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { ArticleService } from './article.service';
import { CreateArticleDto } from './dto/create-article.dto';
import { UpdateArticleDto } from './dto/update-article.dto';
import { ApiTags } from '@nestjs/swagger';

@Controller('article')
@ApiTags('文章接口')
export class ArticleController {
  constructor(private readonly articleService: ArticleService) { }

  @Post()   //创造一篇文章
  create(@Body() createArticleDto: CreateArticleDto) {
    return this.articleService.create(createArticleDto);
  }

  @Get()   //条件匹配查询文章
  findMyAll(@Query() query?: { keyword?: string, uuid?: string, publish_status?: number, right?: string, pageSize?: number, page?: number, limit?: number, orderDto?: { sort: string, order: "ASC" | "DESC" } }) {
    return this.articleService.findArticles(query);
  }




  @Get(':id')//根据id 返回某一篇文章
  findOne(@Param('id') id: string, @Query() query: { uuid: string }) {
    return this.articleService.findOne(+id, query.uuid);
  }

  @Patch(':id')  //修改一篇文章
  update(@Param('id') id: string, @Body() updateArticleDto: UpdateArticleDto) {
    return this.articleService.update(+id, updateArticleDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.articleService.remove(+id);
  }


  //查询浏览记录
  @Post('articleHistory')
  findArticleHistory(@Body() articleHistoryDto: { uuid: string, keyword?: string, page?: number, pageSize?: number }) {
    return this.articleService.findArticleHistory(articleHistoryDto)
  }


  //查询文章评论
  @Post('findArticleComment')
  findArticleComment(@Body() articleIdDto: { articleId: number }) {
    return this.articleService.findArticleComment(articleIdDto.articleId)
  }


  //添加文章评论
  @Post('addArticleComment')
  addArticleComment(@Body() articleCommentDto: { uuid: string, articleId: number, content: string, parentId?: number }) {
    return this.articleService.addArticleComment(articleCommentDto)
  }

  //删除文章评论
  @Post('delArticleComment')
  delArticleComment(@Body() articleCommentDto: { uuid: string, articleId: number, commentId: number }) {
    return this.articleService.delArticleComment(articleCommentDto)
  }

  //点赞文章评论
  @Post('commentFavor')
  commentFavor(@Body() commentFavorDto: { uuid: string, commentId: number, articleId: number }) {
    return this.articleService.commentFavor(commentFavorDto)
  }


}
